package com.qianfeng.demo1.controller;

import com.qianfeng.demo1.util.MyException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {
//    @RequestMapping("/")
//    public String index(){
//        return "/index";
//    }

    @RequestMapping("/login")
    public String login(String username, String password) throws MyException {
        if (username.equals("zhangsan") && password.equals("123456")){
            return "/home";
        }else{
            throw new MyException("E100103");
        }
    }

    @RequestMapping("/add")
    public String add(){
        int i = 5 / 0;
        return "add";
    }

    @RequestMapping("/update")
    public String update(){
        String str = null;
        int i = str.length();
        return "update";
    }

    @RequestMapping("/home")
    public String home(){
        return "/home";
    }

//    只能处理当前类中的异常
//    @ExceptionHandler
//    public String doException(Exception e){
//        return "/error";
//    }
}
